package gui;

import collector.Chain;
import collector.Chunk;
import collector.FileObj;

import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * @author dotekien
 *         Date: Apr 11, 2006
 *         Time: 10:14:58 PM
 */
public class SameComboBoxSelection implements ItemListener {
    GUI gui;

    public SameComboBoxSelection(GUI gui) {
        this.gui = gui;
    }

    public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            Object ob = e.getSource();
            if (ob instanceof JComboBox) {
                JComboBox cb = (JComboBox) ob;
                Object item = cb.getSelectedItem();
                //System.out.println(cb.getSelectedIndex());
                if (item instanceof Chain) {
                    //System.out.println("chain!");
                    gui.updateRighCombo(((Chain) item).getChunks());
                } else if (item instanceof FileObj) {
                    //System.out.println("file");
                    gui.updateRighCombo(((FileObj) item).getChunks());
                } else if (item instanceof Chunk) {
                    //System.out.println("chunk");
                    gui.updateTextWindow((Chunk) item);
                } else {
                    if (item == null) {
                        System.out.println("null");
                    } else {
                        System.out.println("???");
                    }
                }
            }
        }
    }
}
